<template>
  <div class="login-panel">
    <!-- 标题 -->
    <h1 class="title">后台管理系统</h1>
    <!-- 登录面板部分 -->
    <el-tabs v-model="activeTab" type="border-card" stretch>
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon>
              <User />
            </el-icon>
            <span>账号登录</span>
          </span>
        </template>
        <login-account ref="loginAccountRef"></login-account>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon>
              <Iphone />
            </el-icon>
            <span>手机登录</span>
          </span>
        </template>
        手机登录
      </el-tab-pane>
    </el-tabs>
    <!-- 其他操作部分 -->
    <div class="account-control">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <!-- 登录按钮 -->
    <el-button type="primary" class="login-btn" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { watch } from 'vue'
import { ref } from 'vue'
import loginAccount from './login-account.vue'
import { localCache } from '@/cache'
// 控制面板切换
const activeTab = ref('account')
// 记住密码
const isRemPwd = ref(localCache.getItem('isPwd') ?? false)
watch(isRemPwd, (newValue) => {
  localCache.setItem('isPwd', newValue)
})
// 绑定账号登录组件
const loginAccountRef = ref<InstanceType<typeof loginAccount>>()
// 登录操作
const handleLoginClick = () => {
  if (activeTab.value === 'account') {
    loginAccountRef.value?.loginAction(isRemPwd.value)
  } else if (activeTab.value === 'phone') {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  margin-bottom: 150px;
  width: 320px;
  .title {
    text-align: center;
  }
  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
  .custom-tabs-label {
    display: flex;
    align-items: center;
    .el-icon {
      margin-right: 10px;
    }
  }
}
</style>
